package student.systemDB.Dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import student.systemDB.bean.User;

import java.util.List;

@Repository

public class UserDaoImpl implements UserDao{

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
   public int insert() {

        String sql = "insert into students(name,number) values(?,?)";
        int i = jdbcTemplate.update(sql,new Object[]{"张三","123456"});
        return i;
    }

    @Override
    public int delete(String number) {
        String sql = "delete from students where number = ?";
        int i = jdbcTemplate.update(sql,new Object[]{number});
        return i;
    }
   @Override
    public int insert(String name,String number) {
        String sql = "insert into students(name,number) values(?,?)";
        int i = jdbcTemplate.update(sql,new Object[]{name,number});
        return i;
    }
    @Override
    public int update(String name,String number) {
        String sql = "update students set name = ? where number = ?";
        int i = jdbcTemplate.update(sql,new Object[]{name,number});
        return i;
    }

    @Override
    public int update(String name) {
        return 0;
    }

    @Override
    public User select(String number) {
        return null;
    }

    @Override
    public List<User> selectAll() {
        String sql = "select * from students";
        List<User> list = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(User.class));
        return list;
    }




}
